<html>
<head>
	<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
	<script>
		var AKEY = '97';
		var BKEY = '98';
		var ablist;
		var intervalraf;
		var score = 0;
		var interval = 1000;
		var inteval_modificator = 0.8;
		var loose = false;
		function addAB() {
			var ab = 'A';
			if (Math.random() > .5) ab = 'B';
			ablist = $("#ABlist").html() + ab;
			if (ablist.length < 33) {
				inteval_modificator = inteval_modificator + 0.01;
				if (inteval_modificator > 1) inteval_modificator = 1;
    			interval = Math.round(interval * inteval_modificator);
				setTimeout('addAB();', interval);
			} else {
				loose = true;
				$("#youloose").html('Tu as perdu');
			}
			$("#ABlist").html(ablist);
  		}
		$(function() {
			$("body").keypress(function(e) {
				if (!loose) {
					var key = e.which;
					if (ablist.length) {
						if (key == AKEY || key == BKEY) {
							current_first_ablist = ablist.substring(0,1);
							// console.log(current_first_ablist);
							if (AKEY == key && current_first_ablist == 'A') {
								score++;
								ablist = ablist.substring(1);
								$("#ABlist").html(ablist);
							} else if (BKEY == key && current_first_ablist == 'B') {
								score++;
								ablist = ablist.substring(1);
								$("#ABlist").html(ablist);
							} else {
								score-=2;
							}
							$("#score").html(score);
						}
					}
				}
			});
			intervalraf = setTimeout('addAB();', interval);
		});
	</script>
</head>
<body>
<br /><br />
<table>
	<tr>
		<td>[</td>
		<td style="width: 320px;"><span style="font-family: Courier, monospace; font-size: 16px;" id="ABlist">A</span></td>
		<td>]</td>
	</tr>
</table>
Score: <span id="score">0</span><br /><span id="youloose"></span>
</body>
</html>